<?php
namespace api\controllers;

use api\base\BaseApiController;
use common\services\RegionServices;
use Yii;
use yii\filters\VerbFilter;
use yii\web\Response;

/**
 * Site controller
 */
class CommonController extends BaseApiController
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    //'logout' => ['post'],
                ],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

    /**
     * 获取地区列表
     * @return array
     */
    public function actionGetRegion(){
        Yii::$app->response->format = Response::FORMAT_JSON;
        $pid = Yii::$app->request->get('pid');
        $service = new RegionServices();
        $result = $service->getRegion($pid);
        return ['code' => 0, 'data' => $result, 'msg' => 'ok'];
    }

}
